package com.project.service.impl;

import java.util.List;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;

import com.project.dao.GenericDAO;
import com.project.dao.ReaderInfoDAO;
import com.project.entity.ReaderInfo;
import com.project.service.ReaderInfoService;

/**
 * @author jackiel
 * 
 */
@Service("readerInfoService")
public class ReaderInfoServiceImpl extends
		GenericServiceImpl<ReaderInfo, Integer> implements ReaderInfoService {

	private ReaderInfoDAO readerInfoDAO;

	/*
	 * (non-Javadoc)
	 * 
	 * @see
	 * com.project.service.impl.GenericServiceImpl#setGenericDAO(com.project
	 * .dao.IGenericDAO)
	 */
	@Resource(name = "readerInfoDAO")
	@Override
	public void setGenericDAO(GenericDAO<ReaderInfo, Integer> readerInfoDAO) {
		this.genericDAO = readerInfoDAO;
		this.readerInfoDAO = (ReaderInfoDAO) readerInfoDAO;
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see
	 * com.project.service.ReaderInfoService#getUsrInfoByNameAndPsw(java.lang
	 * .String, java.lang.String)
	 */
	@Override
	public ReaderInfo getReaderInfoByNameAndPsw(String name, String password) {
		ReaderInfo readerInfo = readerInfoDAO.getReaderInfoByNameAndPsw(name,
				password);

		if (readerInfo != null) {
			readerInfo.getRoleId().getName();
			readerInfo.getDeptId().getName();
			// readerInfo.setBorrowreturninfoSet(null);
		}

		return readerInfo;
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see com.project.service.ReaderInfoService#getReaderList()
	 */
	@Override
	public List<ReaderInfo> getReaderList() {
		// TODO Auto-generated method stub
		return readerInfoDAO.getReaderList();
	}

	@Override
	public ReaderInfo get(String name) {
		return readerInfoDAO.get(name);
	}

	@Override
	public ReaderInfo getRole(String name) {
		return readerInfoDAO.getRole(name);
	}

	@Override
	public ReaderInfo get(Integer id) {
		ReaderInfo readerInfo = super.get(id);
		readerInfo.getDeptId().getName();
		readerInfo.getRoleId().getName();
		return readerInfo;
	}

}
